#include "../UI/MainWindow.hpp"
#include <chrono>
#include <exception>
#include <iostream>
#include <mutex>
#include <thread>

int main() {
  MainWindow *mainWindow = nullptr;
  std::thread work([&]() {
    std::this_thread::sleep_for(std::chrono::seconds(5));
    if (mainWindow != nullptr) {
      unsigned char *data = new unsigned char[1000 * 1000 * 3];
      memset(data, 0xFF, 1000 * 1000 * 3);
      mainWindow->SetNewImage(1000, 1000, data, 0);
    }
  });
  std::mutex InitMut;
  InitMut.lock();

  std::thread UIThread([&]() {
    auto app = Gtk::Application::create("org.gtkmm.BigScreen.test");
    MainWindow mainUI;
    app->signal_activate().connect([&]() {
      app->add_window(mainUI);
      mainUI.set_visible(true);
      mainWindow = &mainUI;
      InitMut.unlock();
    });
    app->run();
    mainWindow = nullptr;
  });
  InitMut.lock();
  try {
    work.join();
    UIThread.join();
  } catch (const std::exception &e) {
    std::cout << e.what() << std::endl;
  }
}
